package com.ericom.webapp.action;

import java.util.List;

import com.ericom.model.OrderPaymentInfo;
import com.ericom.service.GenericManager;

public class OrderPaymentInfoAction extends BaseAction {
	private GenericManager<OrderPaymentInfo, Long> orderPaymentInfoManager;
	private List orderPaymentInfos;
	private OrderPaymentInfo orderPaymentInfo;
	private Long id;

	public OrderPaymentInfo getOrderPaymentInfo() {
		return orderPaymentInfo;
	}

	public void setOrderPaymentInfo(OrderPaymentInfo orderPaymentInfo) {
		this.orderPaymentInfo = orderPaymentInfo;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setOrderPaymentInfoManager(
			GenericManager<OrderPaymentInfo, Long> orderPaymentInfoManager) {
		this.orderPaymentInfoManager = orderPaymentInfoManager;
	}

	public String list() {
		orderPaymentInfos = orderPaymentInfoManager.getAll();
		return SUCCESS;
	}

	public List getOrderPaymentInfos() {
		return orderPaymentInfos;
	}

	public String delete() {
		orderPaymentInfoManager.remove(orderPaymentInfo.getId());
		this.saveMessage(getText("orderPaymentInfo.deleted"));
		return this.SUCCESS;
	}

	public String edit() {
		if (id != null) {
			orderPaymentInfo = orderPaymentInfoManager.get(id);
		} else {
			orderPaymentInfo = new OrderPaymentInfo();
		}
		return this.SUCCESS;
	}

	public String save() throws Exception {
		if (this.cancel != null) {
			return this.CANCEL;
		}
		if (this.delete != null) {
			return this.delete();
		}

		boolean isNew = (orderPaymentInfo.getId() == null);
		orderPaymentInfo = orderPaymentInfoManager.save(orderPaymentInfo);

		String key = (isNew) ? "orderPaymentInfo.added"
				: "orderPaymentInfo.updated";
		this.saveMessage(getText(key));

		if (!isNew) {
			return this.INPUT;
		} else {
			return this.SUCCESS;
		}
	}
}
